package com.joker.orange.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.joker.common.constant.CacheNames;
import com.joker.common.utils.redis.CacheUtils;
import com.joker.orange.domain.InviteCode;
import com.joker.orange.mapper.InviteCodeMapper;
import com.joker.orange.service.IInviteCodeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.*;

@RequiredArgsConstructor
@Service
public class InviteCodeServiceImpl implements IInviteCodeService {

    private final InviteCodeMapper inviteCodeMapper;

    @Override
    public String selectInviteCodeByRedis() {
        List<InviteCode> configsList = inviteCodeMapper.selectList(new LambdaQueryWrapper<InviteCode>().eq(InviteCode::getIsUse, "1"));
        return configsList.get(0).getInviteCode();
    }

    @Override
    public void insertInviteCode(List<InviteCode> inviteCodeList) {
        inviteCodeMapper.insertBatch(inviteCodeList);
    }

    @Override
    public int updateInviteCode(String inviteCode) {
        return inviteCodeMapper.update(null,
            new LambdaUpdateWrapper<InviteCode>()
                .set(InviteCode::getIsUse, "0")
                .eq(InviteCode::getInviteCode, inviteCode));
    }

}
